package transactions.dq.mail;

import java.io.File;
import java.sql.Types;

import dinamica.GenericTransaction;
import dinamica.Recordset;

public class GetFilesByDir extends GenericTransaction {

	public int service(Recordset inputParams) throws Throwable 
	{
		int rc = super.service(inputParams);
		String fileDir = getConfig().getConfigValue("filedir");
		Recordset rs = new Recordset();
		rs.append("file_all", Types.VARCHAR);
		rs.append("file_name", Types.VARCHAR);
		File dir = new File(fileDir);
		if(dir.isDirectory()){
			File[] files = dir.listFiles();
			if(files != null && files.length > 0){
				for(int i=0;i<files.length;i++){
					rs.addNew();
					File f = files[i];
					rs.setValue("file_all", f.getAbsolutePath());
					rs.setValue("file_name", f.getName());
				}
			}
		}
		publish("files",rs);
		return rc;
	}
}
